package com.jjb.common.task.util;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class JsonUtil {


    public static String toJSONString(Object t) {
        Map<String, Object> jsonMap = new HashMap<>(2);
        jsonMap.put("_c", t.getClass().getTypeName());
        jsonMap.put("_v", t);
        return JSONObject.toJSONString(jsonMap);
    }

    public static Object parse(String content) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(content);
            return jsonObject.getObject("_v", Class.forName(jsonObject.getString("_c")));
        }catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
